﻿' ***********************************************************************
' Assembly         : Ioc
' Author           : Tim Ford
' Created          : 10-02-2013
'
' Last Modified By : Tim Ford
' Last Modified On : 10-02-2013
' ***********************************************************************
' <copyright file="MethodDefinition.vb" company="Red Baron Solutions">
'     Red Baron Solutions. All rights reserved.
' </copyright>
' <summary></summary>
' ***********************************************************************
Imports System.ComponentModel
Imports System.Runtime.Serialization
Imports System.Reflection
Imports System.Globalization
Imports System.Xml.Serialization


Namespace Ioc.DataObjects


    Friend Class MethodDefinition


        Public Sub New()

        End Sub

        Public Sub Fill(methodInfo As MethodInfo, className As String, instanceType As Type)
            MethodName = methodInfo.Name
            ParentClassName = className
            Me.InstanceType = instanceType
            m_MethodInfo = methodInfo
            For Each item As ParameterInfo In methodInfo.GetParameters
                Dim newItem As New MethodSignature
                newItem.Type = item.ParameterType
                newItem.Name = item.Name
                newItem.Position = item.Position
                newItem.IsPrimitive = item.ParameterType.IsPrimitiveType
                Dim cacheKeyMod As Attributes.CacheKeyModificationAttribute = item.GetAttribute(Of Attributes.CacheKeyModificationAttribute)()
                If cacheKeyMod IsNot Nothing Then
                    newItem.DoNotUseAsCacheKey = cacheKeyMod.DoNotUseAsCacheKey
                    newItem.MethodOrPropertyToUseAsCacheKey = cacheKeyMod.MethodOrPropertyToUseAsCacheKey
                End If
                Signature.Add(newItem)
            Next

            ReturnType = methodInfo.ReturnType
            Dim desc As System.ComponentModel.DescriptionAttribute = methodInfo.GetAttribute(Of System.ComponentModel.DescriptionAttribute)()
            If desc IsNot Nothing Then
                Description = desc.Description
            End If

            ReturnTypeIsPrimitive = methodInfo.ReturnType.IsPrimitiveType
        End Sub

        Public Property MethodName() As String

        Public Property ParentClassName() As String

        Public Property InstanceMethodName As String

        Public ReadOnly Property Signature() As List(Of MethodSignature)
            Get
                If m_Signature IsNot Nothing Then
                    Return m_Signature
                End If

                m_Signature = New List(Of MethodSignature)
                Return m_Signature
            End Get
        End Property
        Private m_Signature As List(Of MethodSignature)

        Public Property ReturnType() As Type

        Public Property ReturnTypeIsPrimitive() As Boolean

        Public Property Description() As String

        Public Property IsProperty() As Boolean

        Public Property CanRead() As Boolean

        Public Property CanWrite() As Boolean

        Public Function Method() As MethodInfo
            Return m_MethodInfo
        End Function
        Private m_MethodInfo As MethodInfo

        Public Property InstanceType As Type
    End Class

End Namespace
